/*
 * © Copyright 2011 Romain Marteau, Matthieu Totet
 * 
 *    This file is part of VineaToum.
 *
 *    VineaToum is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VineaToum is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VineaToum.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.vineatoum.view.stateView;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;

import org.vineatoum.business.action.operationactive.Encuvage;
import org.vineatoum.business.action.operationactive.Pressurage;
import org.vineatoum.business.state.Benne;
import org.vineatoum.model.abstraction.IVineaToumModel;
import org.vineatoum.view.action.EncuvagePanel;
import org.vineatoum.view.action.PressuragePanel;
import org.vineatoum.view.component.TrackingPanel;
import org.vineatoum.view.utils.JPanelWrapped;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import com.toedter.calendar.JDateChooser;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.UIManager;
import javax.swing.JCheckBox;
import javax.swing.JButton;

public class BenneActionPanel extends JPanelWrapped {
	private static final long serialVersionUID = -1337740251263111982L;
	
	protected JDateChooser chooserDate;
	protected JSpinner spinnerQuantity;
	protected JSpinner spinnerDensity;
	protected JSpinner spinnerAcidity;
	protected JCheckBox checkBoxTri;
	protected JCheckBox checkBoxFoulage;
	
	private JButton btnEncuver;
	private JButton btnPressurer;
	
	private JPanel pnlData;
	private JPanel pnlButton;
	
	
	
	private IVineaToumModel model;

	/**
	 * Create the panel.
	 * @param benne 
	 * @param model 
	 */
	public BenneActionPanel(IVineaToumModel _model, Benne benne) {
		this.model = _model;

		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		pnlData = new JPanel(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		JLabel lblTitle = new JLabel("Vue Benne");
		pnlData.add(lblTitle, "2, 2");
		
		JLabel lblDate = new JLabel("Date de r\u00E9colte");
		pnlData.add(lblDate, "2, 4, left, default");
		
		chooserDate = new JDateChooser();
		pnlData.add(chooserDate, "4, 4, fill, default");
		
		JLabel lblQuantity = new JLabel("Quantit\u00E9");
		pnlData.add(lblQuantity, "2, 6");
		
		spinnerQuantity = new JSpinner();
		pnlData.add(spinnerQuantity, "4, 6");
		
		JLabel lblDensity = new JLabel("Densit\u00E9");
		pnlData.add(lblDensity, "2, 8");
		
		spinnerDensity = new JSpinner();
		pnlData.add(spinnerDensity, "4, 8");
		
		JLabel lblAcidit = new JLabel("Acidit\u00E9");
		pnlData.add(lblAcidit, "2, 10");
		
		spinnerAcidity = new JSpinner();
		pnlData.add(spinnerAcidity, "4, 10");
		
		JPanel panel = new JPanel();
		panel.setBorder(UIManager.getBorder("InternalFrame.border"));
		panel.setBackground(UIManager.getColor("InternalFrame.borderColor"));
		pnlData.add(panel, "2, 12, 3, 1, fill, fill");
		panel.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		JLabel lblTraitementDuRaisin = new JLabel("Traitement du raisin");
		panel.add(lblTraitementDuRaisin, "2, 2");
		
		checkBoxTri = new JCheckBox("Tri");
		panel.add(checkBoxTri, "2, 4");
		
		checkBoxFoulage = new JCheckBox("Foulage");
		panel.add(checkBoxFoulage, "2, 6");
		
		JLabel lblDureDeLa = new JLabel("Mac\u00E9ration carbonique");
		panel.add(lblDureDeLa, "2, 8");
		
		JSpinner spinner = new JSpinner();
		panel.add(spinner, "4, 8");
		
		JLabel lblHeures = new JLabel("heures");
		panel.add(lblHeures, "6, 8");
		
				
		pnlButton = new JPanel(new FlowLayout(FlowLayout.RIGHT));

		{
			btnPressurer = new JButton("Pressurer");
			btnPressurer.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final PressuragePanel pressurerActionPanel = new PressuragePanel(model, new Pressurage());
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), pressurerActionPanel,
							"Pressurer", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						try {
	
						} catch (ClassCastException e) {
							// TODO: handle exception
							e.printStackTrace();
						}
					}
	
				}
			});
		}
		{
			btnEncuver = new JButton("Encuver");
			btnEncuver.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final EncuvagePanel recolteActionPanel = new EncuvagePanel(model, new Encuvage());
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), recolteActionPanel,
							"Encuvage", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						try {
	
						} catch (ClassCastException e) {
							// TODO: handle exception
							e.printStackTrace();
						}
					}
	
				}
			});
		}
		
		pnlButton.add(btnPressurer);
		pnlButton.add(btnEncuver);
		
		TrackingPanel track = new TrackingPanel(benne);
		
		
		add(pnlData);
		add(pnlButton);
		add(track);
	}

	@Override
	public void doWhenWrapperCancelClick() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doWhenWrapperOkClick() {
		// TODO Auto-generated method stub
		
	}

}
